# 公共代码提取
import os.path
import random

from typing import Final


class _Dirs(object):
    def __init__(self) -> None:
        super().__init__()
        self._here = os.path.abspath(os.path.dirname(__file__))
        self._pimeUserDir = os.path.join(os.path.expandvars('%APPDATA%'), 'PIME')

    @property
    def here(self):
        return self._here

    @property
    def pimeUserDir(self):
        return self._pimeUserDir

    def fileInHere(self, file_or_dir):
        return os.path.join(self._here, file_or_dir)

    def fileInDataDir(self, file):
        return os.path.join(self._here, 'data', file)


Dirs: Final[_Dirs] = _Dirs()


def get_base_file_name(file_name: str) -> str:
    index = file_name.rindex('.')
    if index > 0:
        return file_name[0:index]
    return file_name


def join_path(parent, child):
    return os.path.join(parent, child)


def random_bool():
    return random.randint(0, 2) == 1
